package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.AdminDao;
import com.jxsd.edu.cn.struts2.models.Admin;
import com.jxsd.edu.cn.tools.ResultBean;
import com.jxsd.edu.cn.tools.ResultList;
import com.jxsd.edu.cn.tools.Template;

public class AdminDaoImpl  implements  AdminDao
{

	@Override
	public void addAdmin(Admin admin) 
	{
		String  sql="insert  into  admin(adminID,adminPassword)   values(?,?);";
		Object[]  params={admin.getAdminID(),admin.getAdminPassword()};
		Template  template=new  Template();
		template.update(sql, params);
	}

	@Override
	public void deleteAdmin(String adminId) {
		String  sql="delete  from  admin  where  adminId=?";
		Object[]  params={adminId};
		Template  template=new  Template();
		template.update(sql, params);
	}

	@Override
	public Admin getAdmin(String adminId) {
		ResultBean<Admin>  bean=new ResultBean<Admin>();
		Object[]  params={adminId};
		String  sql="select  adminID,adminPassword  from  admin  where  adminID=?";
		Admin  admin=null;
		try {
			admin=bean.handler(sql, params, Admin.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return admin;
	}

	@Override
	public List<Admin> getAdmins() {
		ResultList<Admin>  hander=new  ResultList<Admin>();
		Object[]  params=null;
		List<Admin>  list=null;
		String  sql="select  adminID,adminPassword  from  admin";
		try {
			list=hander.handler(sql, params, Admin.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
